package com.tangyuan.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tangyuan.common.result.Result;
import com.tangyuan.common.util.CommStatus;
import com.tangyuan.model.activity.HonouredGuest;
import com.tangyuan.model.activity.UserActivity;
import com.tangyuan.model.activity.UserHonouredGuest;
import com.tangyuan.user.service.IHonouredGuestService;
import com.tangyuan.user.service.IUserActivityService;
import com.tangyuan.vo.RuleDetailsVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @Description: user_activity
 * @Author: jeecg-boot
 * @Date: 2024-03-20
 * @Version: V1.0
 */
@Api(tags = "user_activity")
@RestController
@RequestMapping("/user/userActivity")
@Slf4j
public class UserActivityController {
    @Autowired
    private IUserActivityService userActivityService;

    // 发布活动
    @PostMapping("/public")
    public Result<Object> publishActivity(@RequestHeader(name = "userId", required = false) Long userId,
                                          @RequestBody @Valid UserActivity userActivity) {
        return userActivityService.publishActivity(userId, userActivity);
    }

    // 取消报名
    @GetMapping("/cancel")
    public Result<Object> cancelEnroll(@RequestHeader(name = "userId", required = false) Long userId,
                                         @RequestParam Long id) throws IOException {
        return userActivityService.cancelEnroll(userId, id);
    }

    // 确认报名
    @GetMapping("/complete")
    public Result<Object> completeEnroll(@RequestHeader(name = "userId", required = false) Long userId,
                                       @RequestParam Long id) {
        return userActivityService.completeEnroll(userId, id);
    }

    // 嘉宾编辑
    @PostMapping("/edit")
    public Result<Object> editGuest(@RequestHeader(name = "userId", required = false) Long userId,
                                    @RequestBody UserHonouredGuest userHonouredGuest) {
        return userActivityService.editGuest(userId, userHonouredGuest);
    }

    // 我的参加
    @GetMapping("/participation")
    public Result<Object> participateActivity(@RequestHeader(name = "userId", required = false) Long userId) {

        return userActivityService.participateActivity(userId);
    }

    // 我的投票
    @GetMapping("/vote")
    public Result<Object> myVote(@RequestHeader(name = "userId", required = false) Long userId) {

        return userActivityService.myVote(userId);
    }

    // 我的活动
    @GetMapping("/myActivity")
    public Result<Object> myActivity(@RequestHeader(name = "userId", required = false) Long userId) {

        return userActivityService.myActivity(userId);
    }

    // 投票活动预览
    @GetMapping("/previewWithPoster/{id}")
    public Result<Object> previewWithPoster(@RequestHeader(name = "userId", required = false) Long userId
            , @PathVariable("id") Long id) {
        return userActivityService.previewWithPoster(userId, id);
    }

    // 投票规则详情
    @GetMapping("/ruleDetails/{id}")
    public Result<Object> ruleDetails(@PathVariable("id") Long id,
                                      RuleDetailsVo ruleDetailsVo) {

        return userActivityService.ruleDetails(id, ruleDetailsVo);
    }

    @GetMapping("/getHonouredGuestByNumber")
    public com.tangyuan.common.result.Result<Object> getHonouredGuestByNumber(@RequestHeader(name = "userId", required = false) Long userId,
                                                                              @RequestParam(value = "pageSize") Integer pageSize,
                                                                              @RequestParam(value = "pageNum") Integer pageNum,
                                                                              UserActivity userActivity) {
        return userActivityService.getHonouredGuestByNumber(pageNum,pageSize,userId,userActivity);
    }

    @GetMapping("/getHonouredGuestByVoteNum")
    public com.tangyuan.common.result.Result<Object> getHonouredGuestByVoteNum(@RequestHeader(name = "userId", required = false) Long userId,
                                                                               @RequestParam(value = "pageSize") Integer pageSize,
                                                                               @RequestParam(value = "pageNum") Integer pageNum,
                                                                               UserActivity userActivity) {
        return userActivityService.getHonouredGuestByVoteNum(pageNum,pageSize,userId,userActivity);
    }

    //查看是否有活动未通过
    @GetMapping("/checkActiveIsBand")
    public Result checkActiveIsBand(@RequestHeader("userId") Long userId,Long type) {
        return userActivityService.checkActiveIsBand(userId,type);
    }

    //活动审核通过 用户发布活动
    @GetMapping("/publishActive")
    public Result publishActive(@RequestHeader("userId") Long userId, Long id) {
        return userActivityService.publishActive(userId, id);
    }

    @GetMapping("/getAcivity")
    public Result<Object> getActivity(@RequestHeader("userId") Long userId,
                                     @RequestParam(value = "pageSize") Integer pageSize,
                                     @RequestParam(value = "pageNum") Integer pageNum) {
        return userActivityService.getActivity(userId,pageNum,pageSize);
    }

    // 根据活动id查询活动
    @GetMapping("/getActiveById")
    public Result<Object> getActiveById(@RequestHeader(name = "userId", required = false) Long userId,
                                       @RequestParam Long id) throws IOException {
        return userActivityService.getActiveById(userId, id);
    }

    // 根据投票id查询投票 2024/5/28 上午 9:06 By 少帅
    @GetMapping("/getVoteById")
    public Result<Object> getVoteById(@RequestParam Long voteId) {
        return userActivityService.getVoteById(voteId);
    }
}
